package com.znf4.test;

import java.io.InputStream;
import java.net.URL;

import org.apache.tomcat.util.http.fileupload.IOUtils;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

public class SmsSendCommand extends HystrixCommand<String>{

	protected SmsSendCommand() {
		super(HystrixCommandGroupKey.Factory.asKey("smsGroup"));
	}

	@Override
	protected String run() throws Exception {
		URL url = new URL("http://localhost:9001/send/agui");
		byte[] result = new byte[3];
		InputStream input = url.openStream();
		IOUtils.readFully(input, result);
		// 远程服务不稳定或网络抖动时暂时关闭
		return new String(result);
	}
	
	@Override
	protected String getFallback() {
		// 降级 策略  再次查询， 查询备用接口 缓存 mock值
		// 根据业务自定义
		return "降级";
	}

}
